/*
 * 9.7.cpp
 *
 *  Created on: 2012-5-21
 *      Author: jawinton
 */

#include <iostream>
#include <cstring>
#include <cstdio>
#include <cstdlib>

using namespace std;

#define MAX_COUNT 92

int record[MAX_COUNT][8], mark[8], count=0;

void putQueen (int ithQueen) {
	if (ithQueen == 8){
		for (int i=0; i<8; i++)
			record[count][i] = mark[i]+1;
		count++;
		return;
	}
	for (int i=0; i<8; i++) {
		int j;
		for (j=0; j<ithQueen; j++)
			if (mark[j] == i || abs(i-mark[j]) == ithQueen - j) break;
		if (j == ithQueen) {
			mark[ithQueen] = i;
			putQueen(ithQueen+1);
		}
	}
}

int main (void) {
	putQueen(0);
	int n;
	scanf("%d", &n);
	for (int i=0; i<n; i++) {
		int ith;
		scanf("%d", &ith);
		for (int j=0; j<8; j++)
			printf("%d", record[ith-1][j]);
		printf("\n");
	}
	return 0;
}
